I am implementing a very simple solution for "love it" button. I created a database, an index.php and a survey.js. On the Database site everything is working, the mysqli strings are all fine. When the button is clicked the js increase the value +1 to show on index.php.
Problem is that the $_POST['loveit'] to updated the database is not passing and the database at the end is not updated. Here is the index.php:
<html>
<body>
<?php
if ($_POST['loveit']) {
mysqli_query($con,"UPDATE survey2 SET loveit=loveit+1 WHERE id=1");
}
?>
<div class="grid">
<span id="status"></span><br>
<input type="button" value="<?php echo $loveit; ?>" class="button_loveit" id="loveitBtn" />
</div>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/survey.js"></script>
</body>
</html>
and here the survey.js:
$(document).ready(function() {
$("#loveitBtn").removeAttr("disabled");
$('#loveitBtn').click(function(e) {
var val = parseInt($('#loveitBtn').val(), 10);
$.post("../survey/index.php", {op: "loveitBtn"}, function(data) {
$("#status").html("Sucessfully!!");
val = val+1;
$("#loveitBtn").val(val);
$("#loveitBtn").attr("disabled", "disabled");
$("#loveitBtn").css("background-image","url(../survey/like.png)");
});
});
}
Can you please help me to adjust this little code? Am not an expert, I am just starting out learning and I will appreciate any advice. Many thanks Cheers!
You are not passing 'loveit' as a parameter in the data:
$.post("../survey/index.php", {op: "notgood"},function(data)...
Should look like:
$.post("../survey/index.php", {op: "notgood", loveit: "true" },function(data)...